﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Threading;

using MIRIA.UIKit;
using MIRIA.Animations;

namespace MIRIADemo.Pages.MainMenu
{
    public partial class MiriaButton : TButton
    {
        public MiriaButton()
        {
            InitializeComponent();
            //
            //this.Clip = new RectangleGeometry() { Rect = new Rect(new Point(), new Size(this.Width, this.Height)) };
        }

        public void Animate()
        {
            Animator.PlayScript(()=>
            {
                while (true)
                {
                    Animator.FxSuperimpose(_txt_DidYouKnow, 0.0);
                    //
                    _fx_falltop(_txt_Animate, 3.0);
                    // transition between elements
                    Animator.FxSlideLeftIn(_txt_Gestures, 210, 9.0);
                    _fx_slideleftout(_txt_Animate, 4.0);
                    //
                    _fx_slideleftout(_txt_Gestures, 9.0);
                    Thread.Sleep(18000);
                }
            });
        }



        private void _fx_slideleftout(FrameworkElement element, double startdelay)
        {
            Animator.AnimateProperty(element, "X", 0, -210, 0.25, startdelay + 5.0, null);
            Animator.AnimateProperty(element, "Opacity", 1.0, 0.0, 0.25, startdelay + 5.0, delegate(object sender, EventArgs args){
                (sender as FrameworkElement).Visibility = System.Windows.Visibility.Collapsed;
            });        
        }
        private void _fx_falltop(FrameworkElement element, double startdelay)
        {
            Animator.AnimateProperty(element, "X", -210, 0, 0.01, startdelay + 0.0, null);
            Animator.AnimateProperty(element, "Opacity", 0.0, 1.0, 0.25, startdelay + 0.1, null);
            Animator.AnimateProperty(element, "Y", -210, 0, 0.15, startdelay + 0.1, null);
        }


        private void TButton_Loaded(object sender, RoutedEventArgs e)
        {
        }
    }
}
